package com.welsy.authoring.command
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.welsy.authoring.business.*;
	import com.welsy.authoring.model.CourseModelLocator;
	import com.welsy.util.Comparator;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	import mx.controls.Alert;
	import mx.collections.ICollectionView;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.utils.ArrayUtil;
	import com.welsy.authoring.vo.CourseComponentsVO;
	
	/**
	 * @version	$Revision: 1.1 $
	 */
	public class GetCoursesPublishCommand implements ICommand, Responder
	{
	  	public function GetCoursesPublishCommand()
		{	 
		}
	
		public function execute( event : CairngormEvent ): void
		{
			if( CourseModelLocator.getInstance().coursesPublish == null )
			{
			    var delegate : GetCoursesPublishDelegate = new GetCoursesPublishDelegate( this );
			    delegate.getCourses();
			}
		}
	
		public function onResult( event : * = null ) : void
		{				
			trace("fill courses in the model")
			var courses : ICollectionView = ICollectionView( event );
			var model : CourseModelLocator = CourseModelLocator.getInstance();
			
			/* sort the data
			var sort :Sort = new Sort();
		    sort.fields = [ new SortField( "title", true ) ];
		    courses.sort = sort;
		    courses.refresh();
		    */
	   		
			model.coursesPublish = courses;
			//model.workflowState = CourseModelLocator.VIEWING_PRODUCTS_IN_THUMBNAILS;
		}
	
		public function onFault( event : * = null ) : void
		{
			var faultEvent : FaultEvent = FaultEvent( event );
			Alert.show( "Courses could not be retrieved!" );
		}
	}

}